unit clsDB;

interface

uses
  Classes, IBDatabase, IBQuery, DB;

type
  TDBCon = class(TObject)

  private
  dbconn: TIBDatabase;
  query: TIBQuery;
  transaction: TIBTransaction;

  public
  constructor Create();
  function querydb(const sql: String; const return: Boolean): TDataSource;

  end;

implementation

{ TDBCon }

constructor TDBCon.Create;
begin
  inherited;
  { Initialiseer Database en query objecten }
  dbconn := TIBDatabase.Create(dbconn);
  query := TIBQuery.Create(query);
  transaction := TIBTransaction.Create(transaction);

  { Stel parameters in }
  with dbconn do
  begin
    DatabaseName := 'X:\My Documents\NHL\Schaatscase\DB\DB.GDB';
    LoginPrompt := False;
    Params.add('user_name=SCHAATS');
    Params.add('password=case');
  end;
  dbconn.Open();
  query.Database := dbconn;
  {}{}{}{}{}{}{}{}{}
  transaction.AddDatabase(dbconn);
  transaction.StartTransaction();
  dbconn.AddTransaction(transaction);
  query.Transaction := transaction;
  {}{}{}{}{}{}{}{}{}{}
end;

function TDBCon.querydb(const sql: String;
  const return: Boolean): TDataSource;
begin
  if return then
  begin
    query.SQL.Add(sql);
    query.Open();
    querydb := query.DataSource;
    query.Close();
    query.Free();
  end
  else
  begin
    query.SQL.Add(sql);
    query.ExecSQL();
    querydb := query.DataSource;
    query.Close();
    query.Free();
  end;
end;

end.
